package com.ysqcould.web.controller.message;


import com.ysqcould.common.annotation.Log;
import com.ysqcould.common.core.controller.BaseController;
import com.ysqcould.common.core.domain.AjaxResult;
import com.ysqcould.common.core.page.TableDataInfo;
import com.ysqcould.common.enums.BusinessType;
import com.ysqcould.common.utils.poi.ExcelUtil;
import com.ysqcould.message.domain.Invoice;
import com.ysqcould.message.service.IInvoiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 发票申请Controller
 * 
 * @author ruoyi
 * @date 2022-06-30
 */
@RestController
@RequestMapping("/message/invoice")
public class InvoiceController extends BaseController
{
    @Autowired
    private IInvoiceService invoiceService;

    /**
     * 查询发票申请列表
     */
    @PreAuthorize("@ss.hasPermi('message:invoice:list')")
    @GetMapping("/list")
    public TableDataInfo list(Invoice invoice)
    {
        startPage();
        List<Invoice> list = invoiceService.selectInvoiceList(invoice);
        return getDataTable(list);
    }

    /**
     * 导出发票申请列表
     */
    @PreAuthorize("@ss.hasPermi('message:invoice:export')")
    @Log(title = "发票申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Invoice invoice)
    {
        List<Invoice> list = invoiceService.selectInvoiceList(invoice);
        ExcelUtil<Invoice> util = new ExcelUtil<Invoice>(Invoice.class);
        util.exportExcel(response, list, "发票申请数据");
    }

    /**
     * 获取发票申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('message:invoice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(invoiceService.selectInvoiceById(id));
    }

    /**
     * 新增发票申请
     */
    @PreAuthorize("@ss.hasPermi('message:invoice:add')")
    @Log(title = "发票申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Invoice invoice)
    {
        return toAjax(invoiceService.insertInvoice(invoice));
    }

    /**
     * 修改发票申请
     */
    @PreAuthorize("@ss.hasPermi('message:invoice:edit')")
    @Log(title = "发票申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Invoice invoice)
    {
        return toAjax(invoiceService.updateInvoice(invoice));
    }

    /**
     * 删除发票申请
     */
    @PreAuthorize("@ss.hasPermi('message:invoice:remove')")
    @Log(title = "发票申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(invoiceService.deleteInvoiceByIds(ids));
    }
}
